package com.zmj.sy.mom.srv.aps.utils;

import cn.hutool.core.date.DatePattern;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class MkDateTimeUtils {

    /**
     * 相临时间可以重叠 - 相临时间可以重叠 - 用于日历
     * @param start1
     * @param end1
     * @param start2
     * @param end2
     * @return
     */
    public static boolean isOverlappingAbutting(LocalDateTime start1, LocalDateTime end1, LocalDateTime start2, LocalDateTime end2) {
        if(start1 == null || end1 == null || start2 == null || end2 == null){
            throw SyExceptionUtils.e("时间参数不能为空");
        }

        return !start1.isAfter(end2) && !start2.isBefore(end1);
    }

    /**
     * 时间不可以重叠 - 相临时间也不能重叠 - 用于日历
     * @param start1
     * @param end1
     * @param start2
     * @param end2
     * @return
     */
    public static boolean isOverlapping(LocalDateTime start1, LocalDateTime end1, LocalDateTime start2, LocalDateTime end2) {
        return start1.isBefore(end2) && start2.isBefore(end1);
    }

    public static String toString(LocalDate now) {
        if(now == null){
            return null;
        }

        return now.format(DatePattern.NORM_DATE_FORMATTER);
    }

    public static String toString(LocalDate now, String pattern) {
        if(now == null){
            return null;
        }

        return now.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static String toString(LocalDateTime now) {
        if(now == null){
            return null;
        }

        return now.format(DatePattern.NORM_DATETIME_FORMATTER);
    }


    public static String toString(LocalDateTime now, String pattern) {
        if(now == null){
            return null;
        }

        return now.format(DateTimeFormatter.ofPattern(pattern));
    }

}
